<template>
  <div class="">
    <n-upload @before-upload="uploadxl" accept=".xls, .xlsx,.xlsm">
      <n-button type="primary" :loading="dftte">导入</n-button>
    </n-upload>
  </div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const dftte = ref(false);
const uploadxl = (data) => {
  readExcel(data.file.file);
};

const readExcel = (file) => {
  // 解析Excel
  return new Promise(function () {
    // 返回Promise对象
    const reader = new FileReader();
    reader.onload = async (e) => {
      // 异步执行
      var data = e.target.result;
      let wb = window.XLSX.read(data, {
        type: "binary",
      });
      console.log(wb.Sheets.TOTAL);
      console.log(wb.SheetNames);

      let worksheetT = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["TOTAL"])
      );
      let worksheet = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["CASE 1"])
      );
      let worksheetb = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["CASE 2"])
      );
      let worksheetc = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["CASE 3"])
      );
      let worksheetd = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["CASE 4"])
      );
      let worksheete = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets["CASE 5"])
      );
      console.log(worksheetT);
      console.log(worksheet);
      console.log(worksheetb);
      console.log(worksheetc);
      console.log(worksheetd);
      console.log(worksheete);
    };
    reader.readAsBinaryString(file);
  });
};
</script>
<style scoped></style>
